package com.zyf.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.zyf.mapper.DictMapper;
import com.zyf.model.cmn.Dict;
import com.zyf.vo.cmn.DictEeVo;
import org.springframework.beans.BeanUtils;

/**
 * @author zyf
 * @date 2021年05月06日 15:11
 */
public class DictListener extends AnalysisEventListener<DictEeVo> {

    private final DictMapper dictMapper;

    public DictListener(DictMapper dictMapper) {
        this.dictMapper = dictMapper;
    }

    //读取每一行的值
    @Override
    public void invoke(DictEeVo dictEeVo, AnalysisContext context) {
        Dict dict = new Dict();
        if (dictEeVo != null) {
            BeanUtils.copyProperties(dictEeVo,dict);
        }

        dictMapper.insert(dict);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {

    }
}
